package com.foreknow.demo5;

/**
 * 对象数组：数组中保存对象
 */
public class ObjectArray {
    public static void main(String[] args) {
        Employee e1 = new Employee();
        e1.setEid("1001");
        e1.setName("fender");
        e1.setDept("market");
        e1.setSalary(1234.56);

        Employee e2 = new Employee();
        e2.setEid("1002");
        e2.setName("gibson");
        e2.setDept("sale");
        e2.setSalary(5678.56);

        Employee[] arr = new Employee[2];
        //如何向数组中添加元素
        arr[0] = e1;
        arr[1] = e2;
        //如何从数组中获取元素
        Employee emp = arr[0];
        System.out.println(emp.getName()+"---"+emp.getSalary());
        System.out.println("-----------------------------------------------");
        //遍历数组
        for(int i = 0;i<arr.length;i++){
            Employee e = arr[i];
            System.out.println(e.getName()+"---"+e.getSalary());
        }

    }
}
